import { Controller, Get, Post, Body, Patch, Param, Delete,Req } from '@nestjs/common';
import { LoginService } from './login.service';
import { CreateLoginDto } from './dto/create-login.dto';
import { UpdateLoginDto ,ResImageCaptchaDto} from './dto/update-login.dto';
import { UseGuards } from '@nestjs/common';
import { LocalAuthGuard } from 'src/common/guards/local-auth';
import { Request } from 'express';
import { Public } from 'src/common/decorators/public.decorators';

@Controller()
export class LoginController {
  constructor(private readonly loginService: LoginService) {}

  @Post('captchaImage')
  @Public()
  async captchaImage(): Promise<ResImageCaptchaDto>{
    return await this.loginService.createImageCaptcha()
  }
  @Public()
  @UseGuards(LocalAuthGuard)
  
  @Post('login')
  create(@Body() createLoginDto: CreateLoginDto,@Req() request:Request) {
    return this.loginService.login(request);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.loginService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateLoginDto: UpdateLoginDto) {
    return this.loginService.update(+id, updateLoginDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.loginService.remove(+id);
  }
}
